<?php

namespace App\Jobs;

use App\Models\GoldRecord;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use App\Services\RewardGoldPrize\RewardFirstParent;

class RewardFirstParentJob implements ShouldQueue
{
	use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

	public GoldRecord $record;

	public function __construct(GoldRecord $record)
	{
		$this->record = $record;
	}

	public function handle()
	{
		if (app(RewardFirstParent::class)->reward($this->record)) {
			$queue = app()->environment('local') ? 'default' : 'default';
			dispatch(new RewardTeamParentsJob($this->record))->onQueue($queue);
		}
	}
}
